package com.eascs.fp.uc.untils;

import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;

public final class MobileUtils {
	/**
	 * 手机格式正则
	 */
    private static final Pattern MOBILE_PATTERN = Pattern.compile("^(?:13\\d|14\\d|15\\d|17\\d|18\\d)-?\\d{5}(\\d{3}|\\*{3})$");
    
    /**
     * 验证手机号码
     * @param str  手机号码
     * @return
     * @create_time 2014-05-28 下午03:40:00
     */
    public static boolean validateMobile(String mobile) {
    	if(StringUtils.isBlank(mobile)){
    		return false;
    	}
    	return MOBILE_PATTERN.matcher(mobile).matches();
    }
    
    /**
     * 手机号码信息屏蔽
     * @param mobile
     * @return
     */
    public static String closedMobile(String mobile) {
    	if(StringUtils.isBlank(mobile) || mobile.length() < 8){
    		return mobile;
    	}
        return new StringBuffer(mobile.substring(0, mobile.length() - 4)).append("****").toString();
    }
    
}
